package 第五轮工作.辽宁工业大学;

import netscape.javascript.JSObject;
import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;

import java.io.IOException;

public class LNGYDU {
    public static void main(String[] args) throws IOException {
        String url = "";
        for (int i = 0; i < 3; i++) {
            if (i == 0) {
                url = "https://dqxy.lnut.edu.cn/yjspy/dsdw.htm";
            }
            if (i == 1) {
                url = "https://dqxy.lnut.edu.cn/yjspy/dsdw/2.htm";
            }
            if (i == 2) {
                url = "https://dqxy.lnut.edu.cn/yjspy/dsdw/1.htm";
            }
            Connection connect = Jsoup.connect(url);
            Document post = connect.post();
            Element paging = post.getElementById("paging");
            for (Element element : paging.getElementsByTag("li")) {
                for (Element a : element.getElementsByTag("a")) {
                    String attr = a.attr("href");
                    int length = attr.length();
                    String substring = attr.substring(length - 21, length);
                    Connection connect1 = Jsoup.connect("https://dqxy.lnut.edu.cn/" + substring);
                    Document post1 = connect1.post();
                    for (Element main : post1.getElementsByClass("main")) {
                        System.out.println(main.getElementsByClass("detailt").text());
                        int size = main.getElementsByTag("p").size();
//                        System.out.println(main.getElementsByTag("p").text());
//                        System.out.println(main.getElementsByTag("p").get(0).text());
                        if (!main.getElementsByTag("p").get(size - 3).text().equals("")) {
                            System.out.println(main.getElementsByTag("p").get(size - 3).text().trim());
                        }
                        System.out.println(main.getElementsByTag("p").get(size - 2).text().trim());
                    }
                }
            }
        }
    }
}
